//
//  HEOrderAddressCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/10/27.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEOrderAddressCell.h"


@interface HEOrderAddressCell ()

@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *phoneLb;
@property (nonatomic, strong) UILabel *address;
@property (nonatomic, strong) UIButton *editBtn;

@end

@implementation HEOrderAddressCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         self.selectionStyle = UITableViewCellSelectionStyleNone;
         [self initUI];
     }
     return self;;
 }

- (void)initUI {
    
    _nameLb = [UILabel new];
    _nameLb.font = DYFont(18);
    [self.contentView addSubview:_nameLb];
    
    _phoneLb = [UILabel new];
    _phoneLb.font = DYFont(18);
     [self.contentView addSubview:_phoneLb];
    
    _editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _editBtn.titleLabel.font = DYFont(16);
    [_editBtn setTitleColor:CNavBgColor forState:UIControlStateNormal];
    [_editBtn setTitle:@"修改" forState:UIControlStateNormal];
     [self.contentView addSubview:_editBtn];
    [_editBtn addTarget:self action:@selector(selectAddressClick) forControlEvents:UIControlEventTouchUpInside];
    
    _address = [UILabel new];
    _address.numberOfLines = 0;
    _address.font = DYFont(14);
    _address.textColor = CNavSubTitleColor;
     [self.contentView addSubview:_address];
    
    
    [_nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).mas_offset(15);
    }];
    
    [_nameLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [_phoneLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(_nameLb.mas_right).mas_offset(10);
        make.right.equalTo(_editBtn.mas_left).mas_offset(-5);

     }];
    
    [_editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_nameLb);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
    }];
    
    [_address mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLb.mas_bottom).mas_offset(15);
        make.left.equalTo(_nameLb.mas_left);
        make.right.equalTo(self.contentView).mas_offset(-9);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-15);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    self.delegate = formModel.proxyVC;
    _nameLb.text = formModel.order_addres.name;
    _phoneLb.text = formModel.order_addres.phoneNumber;
    _address.text = [NSString stringWithFormat:@"%@%@%@%@",formModel.order_addres.province, formModel.order_addres.city, formModel.order_addres.region, formModel.order_addres.detailAddress];
}

- (void)selectAddressClick {
    if ([_delegate respondsToSelector:@selector(selectAddressWithCell)]) {
        [_delegate selectAddressWithCell];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
